<?php namespace App\Http\Controllers\Home;

use App\Models\Home\FilmHot as FilmHot;
use App\Services\Home\Search\Process;
use Request;

/**
 * 院线热门电影
 */
class HotController extends Controller
{
    /**
     * 电影首页
     */
    public function index()
    {
        $hots = (new FilmHot())->getHots();
        $cacheSecond = config('home.cache_control');
        $time = date('D, d M Y H:i:s', time() + $cacheSecond) . ' GMT';
        $nav_id = 'Tag-index';
        return response(view('home.hot.index', compact('hots')))
            ->header('Cache-Control', 'max-age='.$cacheSecond)
            ->header('Expires', $time);
    }

    /**
     * 最新收录
     */
    public function search($keywords){
        $searchProcess = new Process();
        $films = $searchProcess->search($keywords,1,10);
        /*if( ! empty($films)){
            //取每部电影的标签
            $FilmTagRelationModel = new FilmTagRelationModel();
            foreach($films as $key => $film){
                $films[$key]['tags'] = $FilmTagRelationModel->getTagsByFilmId($film->id);
            }
        }*/
        $nav_id = 'Tag-index';
        return $films['films'];
    }

    /**
     * 电影内页
     */
    public function detail()
    {
        $id = Request::input('id');
        $FilmHotModel = new FilmHot();

        $info = $FilmHotModel->getOneById($id);

        $films = $this->search($info['title']);


        return view('home.hot.detail', compact('info','films'));
    }

}